const fs = require('fs');
const path = require('path');

const folderPath = './svg'
getFile(folderPath)


function getFile (url) {
  const files = fs.readdirSync(url);
  files.forEach(file => {
    // 获取文件的完整路径
    const filePath = path.join(url, file);
    // 判断是否是文件
    if (fs.statSync(filePath).isFile()) {
      if (!filePath.includes('emptyVideo')) {
        setFile(filePath)
      }
    } else {
      getFile(`./${filePath}`)
    }
  });
}

function setFile (path) {
  fs.readFile(`./${path}`, 'utf8', (err, data) => {
    if (err) {
      console.error(err);
      return;
    }
    const fillMatches = data.match(/fill="#([A-Fa-f0-9]{3,6}|[A-Fa-f0-9]{3})"/g);
    // 判断 fillMatches 内容是否全部不同
    let isAllDifferent = true;
    if (fillMatches && fillMatches.length > 1) {
      isAllDifferent = fillMatches.length <= 1 || fillMatches.every(item => item === fillMatches[0]);
    }
    // console.log('fillMatches', fillMatches, isAllDifferent)
    if (isAllDifferent) {
      data = data.replace(/fill="#?[A-Fa-f0-9]{3,6}"/g, '');
      data = data.replace('fill="none"', '');

      // 输出修改后的 SVG 内容
      fs.writeFile(`./${path}`, data, 'utf8', (err) => {
        if (err) {
          console.error(err);
          return;
        }
      });
    }
  });
}
// 读取 SVG 文件


